/*
 *  Copyright (C) 2010 Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * ModAttributes.java
 *
 * Created on 23/12/2010, 12:15:15
 */

package kuasar.plugin.vmcreator.gui.tooltasks.AddHost.devicesFeat;

import java.awt.event.ItemEvent;
import java.util.HashMap;
import javax.swing.tree.DefaultMutableTreeNode;
import kuasar.plugin.vmcreator.gui.tooltasks.AddHost.pn_SetFeatures;

/**
 *
 * @author Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 */

public class ModAttributes extends kuasar.plugin.classMod.AbstractPanel {

    private DefaultMutableTreeNode node;
    private pn_SetFeatures parent;
    private boolean loading;
    private int module;
    /** Creates new form ModAttributes */
    public ModAttributes(DefaultMutableTreeNode node, pn_SetFeatures parent) {
        this.node=node;
        this.parent=parent;
        module = (Integer) ((Object []) node.getUserObject())[0];
        initComponents();
        Load(node);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbl_Type = new javax.swing.JLabel();
        ccb_Cache = new javax.swing.JCheckBox();
        cmb_Type = new javax.swing.JComboBox();

        setOpaque(false);

        lbl_Type.setForeground(new java.awt.Color(204, 204, 204));
        lbl_Type.setText("Type:");

        ccb_Cache.setForeground(new java.awt.Color(204, 204, 204));
        ccb_Cache.setText("Use host I/O cache");
        ccb_Cache.setOpaque(false);
        ccb_Cache.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                ccb_CacheStateChanged(evt);
            }
        });

        cmb_Type.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmb_TypeItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbl_Type)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ccb_Cache)
                    .addComponent(cmb_Type, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(194, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_Type)
                    .addComponent(cmb_Type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addComponent(ccb_Cache)
                .addContainerGap(176, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cmb_TypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmb_TypeItemStateChanged
        if(loading==true)return;
        if(evt.getStateChange()== ItemEvent.DESELECTED) return;
        ((HashMap<String,Object>)((Object[]) node.getUserObject())[2]).put("type", cmb_Type.getSelectedIndex());
    }//GEN-LAST:event_cmb_TypeItemStateChanged

    private void ccb_CacheStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_ccb_CacheStateChanged
        if(loading==true)return;
        ((HashMap<String,Object>)((Object[]) node.getUserObject())[2]).put("cache", ccb_Cache.isSelected());
    }//GEN-LAST:event_ccb_CacheStateChanged

private void Load(DefaultMutableTreeNode node){
    loading=true;
    loadCombo(module);
    cmb_Type.setSelectedIndex((Integer)((HashMap<String,Object>)((Object[]) node.getUserObject())[2]).get("type"));
    ccb_Cache.setSelected((Boolean)((HashMap<String,Object>)((Object[]) node.getUserObject())[2]).get("cache"));
    loading=false;
}
private void loadCombo(int module){
    switch(module){
        case pn_SetFeatures.IDE_MODULE:
            cmb_Type.addItem("PIIX3");
            cmb_Type.addItem("PIIX4");
            cmb_Type.addItem("ICH6");
            break;
        case pn_SetFeatures.SATA_MODULE:
            cmb_Type.addItem("AHCI");
            break;
        case pn_SetFeatures.SCSI_MODULE:
            cmb_Type.addItem("LsiLogic");
            cmb_Type.addItem("BusLogic");
            break;
        case pn_SetFeatures.SAS_MODULE:
            cmb_Type.addItem("LsiLogic SAS");
            break;
        case pn_SetFeatures.FLOPPY_MODULE:
            cmb_Type.addItem("I82078");
            break;
    }
}
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox ccb_Cache;
    private javax.swing.JComboBox cmb_Type;
    private javax.swing.JLabel lbl_Type;
    // End of variables declaration//GEN-END:variables

}
